home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows2 / hp22d3.zip / REFGUIDE / HIERMESS.TXT < prev    next >
Text File  |  1991-05-16  |  18KB  |  439 lines

  1.  
  2.  
  3.  
  4.  
  5.     ________________________________________________________________________
  6.                                     Chapter 3: The Object Hierarchy   29
  7.     ________________________________________________________________________
  8.  
  9.  
  10.     CHAPTER THREE:  THE OBJECT HIERARCHY
  11.  
  12.     Each handler, whose components were discussed in the preceding chapter,
  13.     depends on receiving a specific message in order to execute its
  14.     statements. This section describes HyperPAD's message passing system,
  15.     how messages are sent to objects and what happens when the messages are
  16.     received by objects.
  17.  
  18.     The type and nature of the message and the current object at the time
  19.     the message was generated determines which object  receives the message
  20.     first. The receiving object may or may not have a handler for that
  21.     message. If it does, then the handler for that message executes and the
  22.     message stops its travel. If the object does not have a handler for that
  23.     message, then the message is passed on to the next object in the
  24.     hierarchy. This process continues until there is either a handler for
  25.     that message or the message reaches HyperPAD.
  26.  
  27.     The types of messages and the path that the messages take during their
  28.     travel through HyperPAD (the hierarchy) are discussed in this chapter.
  29.  
  30.  
  31.  
  32.     ________________________________________________________________________
  33.                                     Chapter 3: The Object Hierarchy   30
  34.     ________________________________________________________________________
  35.  
  36.  
  37.     SENDING MESSAGES
  38.  
  39.     Within HyperPAD, script execution is initiated by messages sent to
  40.     objects. Messages are HyperPAD's way of "telling" the objects what's
  41.     taking place in the environment. Messages are sent:
  42.  
  43.         0  When an event occurs (like a key being pressed or mouse button
  44.            being clicked).
  45.  
  46.         0  When the user executes a statement from the message box.
  47.  
  48.         0  When certain commands are executed from within a script, such as:
  49.            beep.
  50.  
  51.         0  When the user selects a menu command.
  52.  
  53.         0  When the system is idle.
  54.  
  55.  
  56.     WHERE DO MESSAGES GO?
  57.  
  58.     When an object receives a message, one of two actions is taken. If the
  59.     object has a handler for that message, the handler is executed and the
  60.     message travel is stopped.
  61.  
  62.     If the object doesn't have a handler for the message, then the message
  63.     is sent to the next object in the object hierarchy. The message will
  64.     continue along in this manner until it encounters a handler for itself,
  65.     or reaches HyperPAD. The following diagram summarizes the path taken by
  66.     a message through HyperPAD:
  67.  
  68.  
  69.  
  70.     ________________________________________________________________________
  71.                                     Chapter 3: The Object Hierarchy   31
  72.     ________________________________________________________________________
  73.  
  74.  
  75.  ┌───────────────────────────────────────────────────────────────────────┐
  76.  │                                                                       │
  77.  │ **** The Printed Documentation has a picture or screen shot here **** │
  78.  │                                                                       │
  79.  └───────────────────────────────────────────────────────────────────────┘
  80.     
  81.  
  82.  
  83.  
  84.     ________________________________________________________________________
  85.                                     Chapter 3: The Object Hierarchy   32
  86.     ________________________________________________________________________
  87.  
  88.  
  89.     The object with the focus receives the message first, which will usually
  90.     be either a page, button, or field. For example, if a button is
  91.     highlighted and the user selects it (by pressing ENTER) a
  92.     select message is sent to the button. If the script doesn't have a
  93.     select handler, the message is sent to the page, and on up the hierarchy
  94.     until a handler is found or the message reaches HyperPAD.
  95.  
  96.     If the message reaches HyperPAD, one of three actions is taken.
  97.  
  98.     1.  The message will be ignored. This happens when there is no handler
  99.     for a system message.
  100.  
  101.     2.  The message will be interpreted by HyperPAD. This happens, for
  102.     example, with the quit message.
  103.  
  104.     3.  An error will be displayed indicating that HyperPAD didn't
  105.     understand the message.
  106.  
  107.  
  108.     TYPES OF MESSAGES
  109.  
  110.     The types of messages that are sent are discussed in this section.
  111.  
  112.  
  113.     SYSTEM MESSAGES
  114.  
  115.     The most common messages passed through HyperPAD are system messages.
  116.     These messages are sent to an object in response to a user-generated
  117.     event. For example, if the pad user presses the left mouse button, the
  118.     mouseDown message is sent to the object under the mouse pointer. Because
  119.     system messages are generated by the pad user, the messages are
  120.     initially sent to either the current page, button, or field. The object
  121.     that first receives the message is called the target.
  122.  
  123.     There are two types of system messages:
  124.  
  125.     1.  Notification messages. These are messages that result from an action
  126.     in the system and whose purpose is to notify a script that an action has
  127.     occurred. Some examples are:
  128.  
  129.     openPage, mouseUp, newPad
  130.  
  131.     Creating handlers for these messages lets you specify actions to be
  132.     performed after the user has completed an action in HyperPAD. For
  133.     example, a mouseUp handler can be used to trigger some actions after the
  134.     mouse button has been physically released.
  135.  
  136.     2.  Normal messages. These messages are sent before any actions have
  137.     been taken and result in an action occurring when the message reaches
  138.     HyperPAD. Normal messages are those that HyperPAD understands, such as
  139.     doMenu, quit, help, beep, and deletePage. For example, if you select
  140.  
  141.  
  142.  
  143.     ________________________________________________________________________
  144.                                     Chapter 3: The Object Hierarchy   33
  145.     ________________________________________________________________________
  146.  
  147.  
  148.     Delete Button on the Edit menu, then the deleteButton command is sent to
  149.     that button. Only when this message is received by HyperPAD will the
  150.     button be deleted.
  151.  
  152.     By creating handlers for these messages, you can control different
  153.     aspects of HyperPAD. For example, the following handler intercepts the
  154.     quit message asking if it is ok to quit. If the user selects Ok, the
  155.     handler passes the message on (so that it will reach HyperPAD and you'll
  156.     exit to DOS). If not, the message stops and HyperPAD doesn't quit.
  157.  
  158.     handler select;
  159.     begin
  160.       answer "Ok to quit?";
  161.       if it is "Ok" then pass;
  162.     end;
  163.  
  164.  
  165.     MESSAGES FROM SCRIPTS
  166.  
  167.     Within your scripts, you can send messages. For example:
  168.  
  169.     handler select;
  170.     begin
  171.       CalculateResult;
  172.     end;
  173.  
  174.     The message calculateResult will be sent to the script of the currently
  175.     executing object. If there is a handler called calculateResult somewhere
  176.     in the message path, it will then be executed.
  177.  
  178.  
  179.     MESSAGE BOX MESSAGES
  180.  
  181.     The message box provides a way of executing statements immediately
  182.     without having to type in a script. When you type in a command and press
  183.     ENTER, one of the following will occur:
  184.  
  185.     1.  If you typed in a command, it will be executed (except the do
  186.     command and any begin...end block).
  187.  
  188.     2.  If you typed in a message and parameters, the message will be sent
  189.     to the current page. If there is a handler for the message, it will be
  190.     executed. If there is no handler, and HyperPAD doesn't recognize the
  191.     message, an error is displayed.
  192.  
  193.     3.  If a valid expression was entered, it is evaluated and the result is
  194.     placed into the message box.
  195.  
  196.  
  197.  
  198.     ________________________________________________________________________
  199.                                     Chapter 3: The Object Hierarchy   34
  200.     ________________________________________________________________________
  201.  
  202.  
  203.     MESSAGES THAT LOOK LIKE COMMANDS
  204.  
  205.     Some commands within scripts are implemented as messages. This may seem
  206.     confusing. For example, you may, at first, be unable to determine if the
  207.     following statement is a command or a message:
  208.  
  209.     beep;
  210.  
  211.     In fact, this is a command that sends a message called beep. When this
  212.     message reaches HyperPAD, a sound is emitted from the system speaker.
  213.  
  214.     All of these special messages are noted in the Chapter Ten.
  215.  
  216.  
  217.     RECEIVING AND SENDING MESSAGES
  218.  
  219.     As you learned above, the initial receiver of a message depends on the
  220.     type and nature of the message as well as which object is currently
  221.     selected when the message is generated.
  222.  
  223.     As senders and receivers of messages, all objects work the same. The
  224.     type of object has no effect on the execution of the script. The
  225.     following outlines the procedure taken when an object receives a
  226.     message:
  227.  
  228.     First, the script is searched for a handler that corresponds to the
  229.     message. If a match is located, that specific handler is executed. After
  230.     a handler executes, the message stops its travel up the hierarchy unless
  231.     it is passed with the pass command. If no matches are found, the message
  232.     is passed to the next object up the hierarchy.
  233.  
  234.  
  235.  
  236.     ________________________________________________________________________
  237.                                     Chapter 3: The Object Hierarchy   35
  238.     ________________________________________________________________________
  239.  
  240.  
  241.  ┌───────────────────────────────────────────────────────────────────────┐
  242.  │                                                                       │
  243.  │ **** The Printed Documentation has a picture or screen shot here **** │
  244.  │                                                                       │
  245.  └───────────────────────────────────────────────────────────────────────┘
  246.     
  247.  
  248.  
  249.     THE EXIT COMMAND
  250.  
  251.     The exit command stops execution of a handler before the last statement
  252.     of the handler has executed. In the following example, the statements
  253.     following the exit statement will never be executed:
  254.  
  255.     handler select;
  256.     begin
  257.       exit;
  258.       beep;
  259.       go to the next page;
  260.     end;
  261.  
  262.     The exit command terminates that message's travel through the hierarchy.
  263.     If you want to stop the execution of all pending handlers, use the exit
  264.     to hyperpad command. This command is similar to the user pressing
  265.     CTRL+BREAK.
  266.  
  267.  
  268.  
  269.     ________________________________________________________________________
  270.                                     Chapter 3: The Object Hierarchy   36
  271.     ________________________________________________________________________
  272.  
  273.  
  274.     The following example uses the exit to hyperpad command to stop the
  275.     display of a sequence of screens. The checkContinue handler below does
  276.     this by stopping all pending handlers, including the calling handler, at
  277.     the user's request.
  278.  
  279.     handler checkContinue;
  280.     begin
  281.       answer "Is it ok to continue?";
  282.       if it is "Cancel" then exit to hyperpad;
  283.     end;
  284.  
  285.     handler select;
  286.     begin
  287.       go to the next page;
  288.       checkContinue;
  289.       go to the next page;
  290.       checkContinue;
  291.       go to pad "phone";
  292.       checkContinue;
  293.       go home;
  294.     end;
  295.  
  296.  
  297.     THE PASS COMMAND
  298.  
  299.     The pass command enables a handler to send the message to the next
  300.     object in the hierarchy, as if the current handler hadn't received it.
  301.     For example, consider the following scripts:
  302.  
  303.     Script:                 Description:
  304.     ---------------------------------------------------------
  305.     handler select;         This message will stop here, and
  306.     begin                   will not go on to the next level in
  307.       :                     the message path.
  308.     end;
  309.  
  310.     handler select;         This script intercepts the message,
  311.     begin                   performs some actions, and then
  312.       :                     passes the message on to be handled
  313.        pass;                by other objects higher in the
  314.     end;                    hierarchy.
  315.  
  316.  
  317.  
  318.     ________________________________________________________________________
  319.                                     Chapter 3: The Object Hierarchy   37
  320.     ________________________________________________________________________
  321.  
  322.  
  323.     The pass command stops execution of a handler. For example, in the
  324.     following script, the beep statement never gets executed:
  325.  
  326.     handler select;
  327.     begin
  328.       pass;
  329.       beep;
  330.     end;
  331.  
  332.     Make sure you position the pass statement as the last statement in the
  333.     script you want executed.
  334.  
  335.  
  336.     ALTERING THE MESSAGE PATH
  337.  
  338.     Messages are normally passed by default up the hierarchy, never across
  339.     to other objects on the same level. With the send command, however, you
  340.     can redirect messages to objects outside the normal hierarchy, such as
  341.     those objects on another page, or lower in the hierarchy.
  342.  
  343.     For example, the following handler redirects the mouseUp message to a
  344.     button on another page:
  345.  
  346.     handler mouseUp;
  347.     begin
  348.       send "mouseUp" to button "Help" of page 2;
  349.     end;
  350.  
  351.  
  352.  
  353.     ________________________________________________________________________
  354.                                     Chapter 3: The Object Hierarchy   38
  355.     ________________________________________________________________________
  356.  
  357.  
  358.     If the receiving object does not contain a handler for that message, the
  359.     message will proceed to travel up that object's hierarchy (not the
  360.     hierarchy of the sending object).
  361.  
  362.  ┌───────────────────────────────────────────────────────────────────────┐
  363.  │                                                                       │
  364.  │ **** The Printed Documentation has a picture or screen shot here **** │
  365.  │                                                                       │
  366.  └───────────────────────────────────────────────────────────────────────┘
  367.     
  368.  
  369.  
  370.  
  371.     ________________________________________________________________________
  372.                                     Chapter 3: The Object Hierarchy   39
  373.     ________________________________________________________________________
  374.  
  375.  
  376.     Messages sent from a script travel up the path of that sending object.
  377.     This is important to remember in cases like the following:
  378.  
  379.     handler mouseUp;
  380.     begin
  381.       go to pad "B";
  382.       calculateTotals;
  383.     end;
  384.  
  385.     Even though the pad has been changed (to pad "B"), the message
  386.     calculateTotals still travels the message path of the original pad.
  387.  
  388.  
  389.     WHERE TO PUT YOUR HANDLERS
  390.  
  391.     Considering all of the stops a message makes on its journey along the
  392.     message path, it may at first be difficult to decide where to put your
  393.     handlers. For example, should you put a handler in the script of a
  394.     button, a  page script, the corresponding background script, the pad
  395.     script, or maybe in the Home pad script? To answer this question, you
  396.     need to determine which objects need to use this handler. Then you will
  397.     know exactly where to locate your handlers.
  398.  
  399.     Simply put, your handlers should be located in the script of the object
  400.     lowest in the hierarchy and still be accessible to all the objects that
  401.     need that handler.
  402.  
  403.     For example, if you have a single button that, when selected, takes you
  404.     to the next page, you would create a handler in the script of the
  405.     button.
  406.  
  407.     Suppose that you have 10 buttons on the page and you want the pad user
  408.     to be able to click on any button and go to the next page. Instead of
  409.     including this handler in the script of each of the ten buttons, you
  410.     could put the handler into the script of the page. Thus, all buttons on
  411.     the page would respond to the select message using the same handler.
  412.     (Remember that if an object doesn't have a handler for a message, it is
  413.     passed on to the next layer...in this case, the page.)
  414.  
  415.     In the next case, suppose that you have a handler called calcResult that
  416.     you would like to access from several different pages which are all on
  417.     the same background. Instead of including the handler in each page
  418.     script that requires it, you could put the handler in the background
  419.     script, making it accessible to every page that uses that background.
  420.  
  421.     Next, suppose that the calcResult handler is used in many different
  422.     pages, buttons and fields throughout your entire pad, even from
  423.     different backgrounds. In this case, you would want to put the handler
  424.     in the pad script, making it accessible to each object in the pad.
  425.  
  426.  
  427.  
  428.     ________________________________________________________________________
  429.                                     Chapter 3: The Object Hierarchy   40
  430.     ________________________________________________________________________
  431.  
  432.  
  433.     In the last case, suppose that the calcResult handler was used in many
  434.     of your pads. Depending on how often it is used, you may want to copy it
  435.     into each pad that uses it. Another approach is to put the handler in
  436.     the pad script of the Home pad. This makes the handler accessible to all
  437.     of your pads. You must be careful, however, to keep this script small
  438.     and efficient because it is always loaded (thus requiring more memory).
  439.